package com.wx.rabbitmq.controller;

import com.wx.rabbitmq.entity.Order;
import com.wx.rabbitmq.producer.RabbitSend;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;


import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName ProducerController
 * @Author wx
 * @Description 生产消息Controller
 * @Date 2018-11-25-21:44
 */
@RestController
public class ProducerController {
    @Autowired
    private RabbitSend rabbitSend;

    @PostMapping("/sendTestMessage")
    public String sendMessage() throws Exception {
        Map<String, Object> properties = new HashMap<>();
        properties.put("number", "12345");
        properties.put("author", "wanxing");
        rabbitSend.send("Hello RabbitMQ For Spring Boot!", properties);
        return "发送成功";
    }


    @PostMapping("/sendTestOrderMessage")
    public String sendTestOrderMessage() throws Exception {
        Order order = new Order("001", "第一个订单");
        rabbitSend.sendOrder(order);
        return "发送成功";
    }

}
